package com.example.demo.arithmetic.datastructure.stack;

import java.util.Scanner;

/**
 * @Description: 数组模拟的栈实现
 * @Author: LLL
 * @Date: 2020-03-14 14:17
 **/
public class MyStack {

    public static void main(String[] args) {

        ArrayStack stack = new ArrayStack(4);
        String key = "";
        boolean loop = true;
        Scanner scanner = new Scanner(System.in);
        while (loop) {
            System.out.println("list:展示数据");
            System.out.println("add:添加数据");
            System.out.println("pop:取出数据");
            System.out.println("exit:退出");
            while (scanner.hasNext()) {
                key = scanner.next();
                switch (key.charAt(0)) {
                    case 'l':
                        stack.list();
                        break;
                    case 'a':
                        int nextInt = scanner.nextInt();
                        stack.push(nextInt);
                        break;
                    case 'p':
                        int pop = stack.pop();
                        System.out.printf("取出的数据为:%d\n", pop);
                        break;
                    case 'e':
                        scanner.close();
                        loop = false;
                        break;
                    default:
                        break;
                }
            }
        }

    }
}
